//
//  MBChatAvatarListCell.m
//  Meboo
//
//  Created by kyo on 2023/10/16.
//

#import "MBChatAvatarListCell.h"

@interface MBChatAvatarListCell()
@property(nonatomic,strong)UIImageView *avatarImageView;
@property (nonatomic, strong) UIImageView *stateView;
@end

@implementation MBChatAvatarListCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setModel:(MBChatNewFriendsModel *)model {
    _model = model;
    [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:model.avatarUrl]];
    if (model.online) {
        self.stateView.hidden = NO;
    } else {
        self.stateView.hidden = YES;
    }
}

#pragma mark - UI
- (void)setupUI {
    self.contentView.backgroundColor = HEXS(@"22253C");
    
    [self.contentView addSubview:self.avatarImageView];
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];

    [self.contentView addSubview:self.stateView];
    [self.stateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.avatarImageView.mas_bottom);
        make.centerX.equalTo(self.avatarImageView);
        make.height.mas_equalTo(MBHeightScale(14));
    }];
}

#pragma mark - Setter && Getter
- (UIImageView *)avatarImageView {
    if (!_avatarImageView) {
        _avatarImageView = [UIImageView new];
        _avatarImageView.layer.cornerRadius = MBHeightScale(33);
        _avatarImageView.layer.masksToBounds = YES;
        _avatarImageView.image = [UIImage imageNamed:@"home_icon_self"];
    }
    return _avatarImageView;
}

- (UIImageView *)stateView {
    if (!_stateView) {
        _stateView = [UIImageView new];
        _stateView.image = ImageWithName(@"chat_state");
        _stateView.hidden = YES;
    }
    return _stateView;
}
@end
